a = [1,2,3,4]
a.unshift(0)
puts "-------------------------"
puts a 

a = [1,2,3,4]
a.push(5)
puts "-------------------------"
puts a

a << 5
puts "-------------------------"
puts a 

puts "-------------------------"
array = [1,2,[3,4,[5],[6,[7,8]]]]
p array.flatten
puts "-------------------------"
p array.flatten(1)
puts "-------------------------"
p array.flatten(2)
puts "-------------------------"
a = %w{ one two three}
p a * "-"
puts "-------------------------"
p [1,2,3,1,4,3,5,1].uniq

hash = {"red" => "ruby","white"=>"diamond","green"=>"emerald"}
hash.each.with_index{|(key,value),i|
	puts "Pair #{i} is: #{key}/#{value}"
}
n = 0
puts Array.new(3) {n += 1;n*10}

string = "A string"
puts string.respond_to?(:to_ary)
puts string.respond_to?(:to_a)
puts Array(string)

def string.to_a
	split(//)
end
puts Array(string)
#字符串数组
puts %w{David A. Black}
puts %w{David\ A.\ Black is a Rubyist.}
puts %W{ David is #{2014 - 1959} years old.}
#符号数组
puts %i{ a b c}
d = "David"
puts %I{"#{d}"}

obj = Object.new
puts Array.try_convert(obj)

def obj.to_ary
	[1,2,3]
end

puts Array.try_convert(obj)

def obj.to_ary
	"Not an array!"
end

puts Array.try_convert(obj)

a = []
a[0] = "first"
a = [1,2,3,4,5]
p a[2]

array = ["the","dog","ate","the","cat"]
articles = array.value_at(0,3)
p articles






